package com.bf.xpdd.util;

import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;

/**
 * 判断编码
 * @author Fantastic
 * @version 1.0.0 2011-7-16
 * @since 1.0.0
 */
public class CharsetUtility {

	/**
	 * 判断编码
	 * 
	 * @param b
	 * @param csnam
	 * @return
	 */
	public static boolean validateCharset(byte[] b, String csnam)
	{
		CharsetDecoder cd = Charset.availableCharsets().get(csnam).newDecoder();
		try 
		{
			cd.decode(ByteBuffer.wrap(b));
		} 
		catch (CharacterCodingException e) 
		{
			return false;
		}
		return true;
	}

}
